var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var { cors } = require('./filter/index');
var indexRouter = require('./routes/index');
var adminRouter = require('./routes/admin');
// var hotTVRouter = require('./routes/hotTV');
// var AmericanRouter = require('./routes/American');
// var BritainRouter = require('./routes/Britain');
// var ChinaRouter = require('./routes/China');
// var HongKongRouter = require('./routes/HongKong');
// var JapanRouter = require('./routes/Japan');
// var JapaneseAnimationRouter = require('./routes/JapaneseAnimation');
// var varietyRouter = require('./routes/variety');
// var documentaryRouter = require('./routes/documentary');
// var SouthKoreaRouter = require('./routes/SouthKorea');


var detailRouter = require('./routes/detail');
var getTVRouter = require('./routes/getTV');
var patchTVRouter = require('./routes/patchTV');
var deleteTVRouter = require('./routes/deleteTV');
var addTVRouter = require('./routes/addTV');
var getuserRouter = require('./routes/getuser');
var getRateRouter = require('./routes/getRate');
// var varietyRouter = require('./routes/variety');
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors);
app.use('/', indexRouter);
app.use('/admin', adminRouter);
// app.use('/hotTV', hotTVRouter);
// app.use('/AmericanTV', AmericanRouter);
// app.use('/BritainTV', BritainRouter);
// app.use('/ChinaTV', ChinaRouter);
// app.use('/HongKongTV', HongKongRouter);
// app.use('/JapanTV', JapanRouter);
// app.use('/varietyTV', varietyRouter);
// app.use('/JapaneseAnimationTV', JapaneseAnimationRouter);
// app.use('/documentaryTV', documentaryRouter);
// app.use('/SouthKoreaTV', SouthKoreaRouter);


app.use('/detailTv', detailRouter);
app.use('/getTVlist', getTVRouter);
app.use('/patchTVlist', patchTVRouter);
app.use('/deleteTVlist', deleteTVRouter);
app.use('/addTVlist', addTVRouter);
app.use('/getuserlist', getuserRouter);
app.use('/getRatelist', getRateRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
